#pragma once

class CFileIOTask;

class CFileIOManager
{
public:
	CFileIOManager();
	~CFileIOManager();

	static CFileIOManager *Get() { return m_pThis; }

	bool Init();
	void Exit();
	void AddAndRunTask(const std::shared_ptr<CFileIOTask>& pTask);
	void RemoveTask(UINT nTaskId);

private:
	void CancelTasks();

	static CFileIOManager *m_pThis;

	HANDLE   m_hExitEvent;
	LockExit m_lockExit;	// Prevent FileIOManager thread from exiting
	SRWLOCK  m_SRWLock = SRWLOCK_INIT;
	std::unordered_map<UINT, std::weak_ptr<CFileIOTask>> m_mapTasks;
};
